<?php

	require_once(APPPATH . 'controllers/base_controllers/base_validation_controller.php');
	
	class Member_registration_validation extends Base_validation_controller
	{
		
		public function __construct()
		{
			parent::__construct();
			
			$this->load->library('validation');
			$this->load->model('values/cwr_registrant_member_homepage_value');
		}
			
		public function validate_step1()
		{
			$this->load->model('proxies/Walk_proxy');
			$currentyear = $this->Walk_proxy->getCurrentYear();
			
			/*
			$rules['userName'] = "trim|required|callback_valid_user_name_check|max_length[32]";
			$rules['password'] = "trim|required|min_length[6]";
			*/
			
			//Which CMB center
			$rules['cmbCenter'] = "trim|required";			
			
			if( $this->input->post('cmbCenter') != "" )
			{
				$cmb_center = $this->input->post('cmbCenter');
				if( $this->input->post('cmbCenter') == "Andover" )
				{
					//Primary member
					$rules['firstName']	= "trim|required|alpha_dash|min_length[1]|max_length[31]";
					$rules['lastName'] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
					$rules['question'] = "trim|required|alpha_dash|min_length[1]|max_length[33]";
					$rules['secretPhrase'] = "trim|required|alpha_dash|min_length[1]|max_length[63]";
					$rules['gender'] = "trim|required";
					$rules['primaryEmail'] = "trim|required|valid_email|matches[primaryEmailConfirm]|max_length[127]";
					$rules['primaryEmailConfirm'] = "trim|required|valid_email|max_length[127]";
					$rules['homePhoneNumber'] = "trim|required|callback_valid_phone_check|max_length[12]";
					$rules['mobilePhoneNumber'] = "trim|required|callback_valid_phone_check|max_length[12]";
					if ( $this->input->post('company') != "" )
						$rules['company'] = "trim|required";
						
					//Spouse
           	 		if( $this->input->post('spouseFirstName') != "" )
					{
						$rules['spouseFirstName'] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
						$rules['spouseLastName'] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
						$rules['spouseGender'] = "trim|required";
						$rules['spouseEmail'] = "trim|required|valid_email|matches[spouseEmailConfirm]|max_length[127]";
						$rules['spouseEmailConfirm'] = "trim|required|valid_email|max_length[127]";
						$rules['spousePhone'] = "trim|required|callback_valid_phone_check|max_length[12]";
						$rules['spouseMobilePhone'] = "trim|required|callback_valid_phone_check|max_length[12]";
					}
			
					$rules['homeAddress1'] = "trim|required|alpha_address|min_length[1]|max_length[127]";
					if ($this->input->post('homeAddress2') != "")
						$rules['homeAddress2'] = "trim|alpha_address|max_length[127]";
					$rules['city'] = "trim|required|alpha_dash|min_length[1]|max_length[63]";
					$rules['state'] = "trim|required";
					$rules['zipCode'] = "trim|required|callback_valid_zip_code_check|max_length[10]";
			
					//$rules['lifeMember'] = "trim|required";
					$rules['primaryAttendSatsang'] = "trim|required";

					//$rules['donationopt'] = "trim|required";
					
		          	$invgrdarr1 = array('10','11','12');
                    $invgrdarr = array('9','10','11','12');
                    $invgrdarr2 = array('Pre-K','10','11','12');
					//Children
           	 		if( $this->input->post('numChildren') > 0 )
					{
						for( $i = 1; $i <= $this->input->post('numChildren'); $i++ )
						{
							$rules['childFN' . $i] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
							$rules['childLN' . $i] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
							$rules['childG' . $i] = "trim|required";
							if ($this->input->post('childEM' . $i) != "")
								$rules['childEM' . $i] = "trim|required|valid_email|max_length[127]";
							$rules['childDOB' . $i] = "trim|required|valid_date[m/d/y,/]";
							$rules['childGrade' . $i] = "trim|required";
							
                            //Only allow Pre-K and 10-12 for AM session at Andover
                            /* if (!in_array($this->input->post('childGrade'.$i),$invgrdarr2) and ($this->input->post('childSession'.$i) == "AM"))
                            {
                                echo("<b>ONLY GRADES Pre-K AND (10-12) SUPPORTED FOR AM SESSION</b>");
                                die;
                            } */

							//Don't allow 10-12 grades for PM session at Andover
							if (in_array($this->input->post('childGrade'.$i),$invgrdarr1) and ($this->input->post('childSession'.$i) == "PM"))
							{
								echo("<b>GRADES 10-12 NOT AVAILABLE FOR PM SESSION</b>");
								die;
							}

                            //Don't allow 9-12 grades for PM2 session at Andover
                            if (in_array($this->input->post('childGrade'.$i),$invgrdarr) and ($this->input->post('childSession'.$i) == "PM2"))
                            {
                                echo("<b>GRADES 9-12 NOT AVAILABLE FOR PM2 SESSION</b>");
                                die;
                            }

							$rules['childSession' . $i] = "trim|required";

							//Check if particular grade/session/center is full
							if ($this->Walk_proxy->isClassFull($currentyear, $cmb_center, $this->input->post('childGrade'.$i), $this->input->post('childSession'.$i)))
							{
								echo("<b>CLASS FULL</b> for Center: ".$cmb_center.", Grade: ".$this->input->post('childGrade'.$i).", Session: ".$this->input->post('childSession'.$i));
								die;
							}

                            if (!$this->Walk_proxy->isValidDOB($this->input->post('childDOB' . $i)))
                            {
                                echo("<b>Child #".$i." DOB must be on or before ".$this->config->item('dob_thr_date')."</b>");
                                die;
                            }
							/*
							if( isset( $_POST['child' . $i . 'Lang'] ) )
							{
								for( $j = 1; $j <= 7; $j++ )
								{
									if($this->input->post('child' . $i . 'LangLevel' . $j) )
										$rules['child' . $i . 'LangLevel' . $j] = "trim|required";
								}
							}
							*/
						}
					}
					
					$rules['donationamount'] = "trim|numeric|max_length[8]";
				}
				else
				{
					//Primary member
					$rules['firstName1']	= "trim|required|alpha_dash|min_length[1]|max_length[31]";
					$rules['lastName1'] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
					$rules['question1'] = "trim|required|alpha_dash|min_length[1]|max_length[33]";
					$rules['secretPhrase1'] = "trim|required|alpha_dash|min_length[1]|max_length[63]";
					$rules['gender1'] = "trim|required";
					$rules['primaryEmail1'] = "trim|required|valid_email|matches[primaryEmail1Confirm]|max_length[127]";
					$rules['primaryEmail1Confirm'] = "trim|required|valid_email|max_length[127]";
					$rules['homePhoneNumber1'] = "trim|required|callback_valid_phone_check|max_length[12]";
					$rules['mobilePhoneNumber1'] = "trim|required|callback_valid_phone_check|max_length[12]";
					if ( $this->input->post('company1') != "" )
						$rules['company1'] = "trim|required";
						
					//Spouse
           	 		if( $this->input->post('spouseFirstName') != "" )
					{
						$rules['spouseFirstName1'] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
						$rules['spouseLastName1'] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
						$rules['spouseGender1'] = "trim|required";
						$rules['spouseEmail1'] = "trim|required|valid_email|matches[spouseEmail1Confirm]|max_length[127]";
						$rules['spouseEmail1Confirm'] = "trim|required|valid_email|max_length[127]";
						$rules['spousePhone1'] = "trim|required|callback_valid_phone_check|max_length[12]";
						$rules['spouseMobilePhone1'] = "trim|required|callback_valid_phone_check|max_length[12]";
					}
			
					$rules['homeAddress1mw'] = "trim|required|alpha_address|min_length[1]|max_length[127]";
					if ($this->input->post('homeAddress2mw') != "")
						$rules['homeAddress2mw'] = "trim|alpha_address|max_length[127]";
					$rules['city1'] = "trim|required|alpha_dash|min_length[1]|max_length[63]";
					$rules['state1'] = "trim|required";
					$rules['zipCode1'] = "trim|required|callback_valid_zip_code_check|max_length[10]";
			
					//$rules['lifeMember1'] = "trim|required";

					//$rules['donationopt1'] = "trim|required";
					
					//Children
           	 		if( $this->input->post('numChildren1') > 0 )
					{
						for( $i = 1; $i <= $this->input->post('numChildren1'); $i++ )
						{
							$rules['childFNmw' . $i] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
							$rules['childLNmw' . $i] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
							$rules['childGmw' . $i] = "trim|required";
							if ($this->input->post('childEMmw' . $i) != "")
								$rules['childEMmw' . $i] = "trim|required|valid_email|max_length[127]";
							$rules['childDOBmw' . $i] = "trim|required|valid_date[m/d/y,/]";
							$rules['childGrademw' . $i] = "trim|required";
							if ($this->Walk_proxy->isClassFull($currentyear, $cmb_center, $this->input->post('childGrademw'.$i), $this->input->post('childSessionmw'.$i)))
							{
								echo("<b>CLASS FULL</b> for Center: ".$cmb_center.", Grade: ".$this->input->post('childGrademw'.$i).", Session: ".$this->input->post('childSessionmw'.$i));
								die;
							}

                            if (!$this->Walk_proxy->isValidDOB($this->input->post('childDOBmw' . $i)))
                            {
                                echo("<b>Child #".$i." DOB must be on or before ".$this->config->item('dob_thr_date')."</b>");
                                die;
                            }
							/*
							if( isset( $_POST['child' . $i . 'Lang'] ) )
							{
								for( $j = 1; $j <= 7; $j++ )
								{
									if($this->input->post('child' . $i . 'LangLevel' . $j) )
										$rules['child' . $i . 'LangLevel' . $j] = "trim|required";
								}
							}
							*/
						}
					}
					
					$rules['donationamount1'] = "trim|numeric|max_length[8]";				
				}
			}
			
			$this->validation->set_rules($rules);
			
			$validationPassed = $this->validation->run();
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_for_step1( $this->validation->error_string ) );
			}
			
			die;
		}
		
		public function validate_register_members()
		{
			echo( 'VALIDATION_SUCCESS' );			
		}
		
		public function validate_release_check()
		{
			$this->load->model('proxies/Walk_proxy');

			//Get check info
			$curyear = $this->Walk_proxy->getCurrentYear();
			$RegIdArray = $this->Walk_proxy->getUnpaidCheckRegId( $curyear );

			if (count($RegIdArray) > 0)
			{
				$flg = false;
				//CheckInfo
				for( $i = 0; $i < count($RegIdArray); $i++ )
				{
					$checknum = $this->input->post('crhid'.$RegIdArray[$i]);
					if ($checknum != "")
					{
						$rules['crhid'.$RegIdArray[$i]] = "trim|required|alpha_dash|min_length[1]|max_length[16]";
						$flg = true;
					}
				}
			
				if ($flg)
				{
					$this->validation->set_rules($rules);	
					$validationPassed = $this->validation->run();
				}
				else
					$validationPassed = true;
			}
			else
			{
				$validationPassed = true;
			}
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_release_check( $this->validation->error_string, $RegIdArray ) );
			}
			
			die;
		}
		
		public function validate_edit_account()
		{			
			if( $this->input->post('password') != "" )
			{
				$rules['password'] = "trim|required|matches[passconf]|min_length[6]|max_length[16]";
				$rules['passconf'] = "trim|required|min_length[6]|max_length[16]";
			}
			
			//Primary member
			$rules['question'] = "trim|required|min_length[1]|max_length[31]";
			$rules['secretPhrase'] = "trim|required|min_length[1]|max_length[63]";
			$rules['primaryEmail'] = "trim|required|valid_email|matches[primaryEmailConfirm]|max_length[127]";
			$rules['primaryEmailConfirm'] = "trim|required|valid_email|max_length[127]";
			$rules['homePhoneNumber'] = "trim|required|callback_valid_phone_check|max_length[12]";
			$rules['mobilePhoneNumber'] = "trim|required|callback_valid_phone_check|max_length[12]";
						
			//Spouse
           	 if( $this->input->post('spouseEmail') != "" )
			{
				$rules['spouseEmail'] = "trim|required|valid_email|matches[spouseEmailConfirm]|max_length[127]";
				$rules['spouseEmailConfirm'] = "trim|required|valid_email|max_length[127]";
			}
				
           	 if( $this->input->post('spousePhone') != "" )
			{
				$rules['spousePhone'] = "trim|required|callback_valid_phone_check|max_length[12]";
			}

           	 if( $this->input->post('spouseMobilePhone') != "" )
			{
				$rules['spouseMobilePhone'] = "trim|required|callback_valid_phone_check|max_length[12]";
			}
			
			$rules['homeAddress1'] = "trim|required|alpha_address|min_length[1]|max_length[127]";
			if ($this->input->post('homeAddress2') != "")
				$rules['homeAddress2'] = "trim|alpha_address|min_length[1]|max_length[127]";
			$rules['city'] = "trim|required|alpha_dash";
			$rules['state'] = "trim|required";
			$rules['zipCode'] = "trim|required|callback_valid_zip_code_check";
			
			
			$this->validation->set_rules($rules);
			
			$validationPassed = $this->validation->run();
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_for_edit_account( $this->validation->error_string ) );
			}
			
			die;
		}

		public function validate_admin_edit_account()
		{			
			//Primary member
			$rules['primaryEmail'] = "trim|required|valid_email|matches[primaryEmailConfirm]|max_length[127]";
			$rules['primaryEmailConfirm'] = "trim|valid_email|max_length[127]";
			$rules['homePhoneNumber'] = "trim|callback_valid_phone_check|max_length[12]";
			$rules['mobilePhoneNumber'] = "trim|callback_valid_phone_check|max_length[12]";
						
			//Spouse
           	 if( $this->input->post('spouseEmail') != "" )
			{
				$rules['spouseEmail'] = "trim|valid_email|matches[spouseEmailConfirm]|max_length[127]";
				$rules['spouseEmailConfirm'] = "trim|valid_email|max_length[127]";
			}
				
           	 if( $this->input->post('spousePhone') != "" )
			{
				$rules['spousePhone'] = "trim|callback_valid_phone_check|max_length[12]";
			}

           	 if( $this->input->post('spouseMobilePhone') != "" )
			{
				$rules['spouseMobilePhone'] = "trim|callback_valid_phone_check|max_length[12]";
			}
			
			$rules['homeAddress1'] = "trim|alpha_address|min_length[1]|max_length[127]";
			if ($this->input->post('homeAddress2') != "")
				$rules['homeAddress2'] = "trim|alpha_address|min_length[1]|max_length[127]";
			$rules['city'] = "trim|alpha_dash";
			$rules['state'] = "trim";
			$rules['zipCode'] = "trim|callback_valid_zip_code_check";
			
			
			$this->validation->set_rules($rules);
			
			$validationPassed = $this->validation->run();
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_for_admin_edit_account( $this->validation->error_string ) );
			}
			
			die;
		}

		public function validate_register_existing_member( $urlKey )
		{
			$this->load->model('proxies/Person_proxy');
			$this->load->model('proxies/Walk_proxy');
			$this->load->model('proxies/Paypal_proxy');

			$currentyear = $this->Walk_proxy->getCurrentYear();
			$this->load->model('values/cwr_registrant_member_homepage_value');
			$this->load->model('proxies/Cwr_registrant_member_proxy');

			//Check if already registered
			$CMBRegHistoryId = $this->Walk_proxy->getCMBRegHistoryIdfromURLYear( $urlKey, $currentyear );
			if ($CMBRegHistoryId > 0)
			{
				echo( 'VALIDATION_SUCCESS' );
				die;
			}
			
			$cwr_registrant_home_value = Cwr_registrant_member_homepage_value::cast($this->Cwr_registrant_member_proxy->getRegistrantMemberHomepageFromUrl_noyr( $urlKey ));

			//Primary member
			/* if($cwr_registrant_home_value->getCMBCenter() == "Andover")
			{
				$rules['primaryAttendSatsang'] = "trim|required";
			} */
						
			//Household
			//
			
           	$invgrdarr = array('9','10','11','12');
            $invgrdarr1 = array('10','11','12');
			//Children
			$cmb_center = $cwr_registrant_home_value->getCMBCenter();
			$numChildren = count($cwr_registrant_home_value->getChildInfo());
			$i = 0;
			if( $numChildren > 0 )
			{
				$childInfoArray = $cwr_registrant_home_value->getChildInfo();

				for( $k = 0; $k < $numChildren; $k++ )
				{
					$childInfo = $childInfoArray[$k];
					
					if ($childInfo[7] == "1")
					{
						if ($this->input->post('childRemove'.($i+1)) == "No")
						{
							if($cmb_center == "Andover")
							{
								$rules['childSession'.($i+1)] = "trim|required";

                                //Allow AM session for existing students
								/* //Don't allow 10-12 grades for PM session at Andover
								if (in_array($this->input->post('childGrade'.($i+1)),$invgrdarr1) and ($this->input->post('childSession'.($i+1)) == "PM"))
								{
									echo("<b>GRADES 10-12 NOT AVAILABLE FOR PM SESSION</b>");
									die;
								}
                                
                                //Don't allow 9-12 grades for PM2 session at Andover
                                if (in_array($this->input->post('childGrade'.($i+1)),$invgrdarr) and ($this->input->post('childSession'.($i+1)) == "PM2"))
                                {
                                    echo("<b>GRADES 9-12 NOT AVAILABLE FOR PM2 SESSION</b>");
                                    die;
                                } */
							}
					
							$rules['childGrade'.($i+1)] = "trim|required";
							
							//Check if particular grade/session/center is full
							if ($this->Walk_proxy->isClassFull($currentyear, $cmb_center, $this->input->post('childGrade'.($i+1)), $this->input->post('childSession'.($i+1))))
							{
								echo("<b>CLASS FULL</b> for Center: ".$cmb_center.", Grade: ".$this->input->post('childGrade'.($i+1)).", Session: ".$this->input->post('childSession'.($i+1)));
								die;
							}
							
                            if (!$this->Walk_proxy->isValidDOB($this->input->post('existChildDOB' . ($i+1))))
                            {
                                echo("<b>Child #".($i+1)." DOB must be on or before ".$this->config->item('dob_thr_date')."</b>");
                                die;
                            }

							$rules['existChildEmail'.($i+1)] = "trim|required|valid_email|max_length[127]";
						}
					
						$i ++;
					} //if ($childInfo == "1")
				} //for( $k = 0; $k < $numChildren; $k++ )
			}
			$numEnabledChildren = $i;
					
			//Additional Children
           	if ((6-$numEnabledChildren) > 0)
			{
				if ($this->input->post('numChildren') != "")
				{
					$numAddChildren = $this->input->post('numChildren');
					for( $i = ($numEnabledChildren + 1); $i < ($numEnabledChildren + $numAddChildren + 1); $i++ )
					{
						$rules['childFN' . $i] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
						$rules['childLN' . $i] = "trim|required|alpha_dash|min_length[1]|max_length[31]";
						$rules['childG' . $i] = "trim|required";
						if ($this->input->post('childEM' . $i) != "")
							$rules['childEM' . $i] = "trim|required|valid_email|max_length[127]";
						$rules['childDOB' . $i] = "trim|required|valid_date[m/d/y,/]";
						
						if($cwr_registrant_home_value->getCMBCenter() == "Andover")
						{
							$rules['childSession' . $i] = "trim|required";
							
                            //Allow AM session for existing students	
							/* //Don't allow 10-12 grades for PM session at Andover
							if (in_array($this->input->post('childGrade'.$i),$invgrdarr1) and ($this->input->post('childSession'.$i) == "PM"))
							{
								echo("<b>GRADES 10-12 NOT AVAILABLE FOR PM SESSION</b>");
								die;
							}

                            //Don't allow 9-12 grades for PM2 session at Andover
                            if (in_array($this->input->post('childGrade'.$i),$invgrdarr) and ($this->input->post('childSession'.$i) == "PM2"))
                            {
                                echo("<b>GRADES 9-12 NOT AVAILABLE FOR PM2 SESSION</b>");
                                die;
                            } */
						}
						
						$rules['childGrade' . $i] = "trim|required";
						//Check if particular grade/session/center is full
						if ($this->Walk_proxy->isClassFull($currentyear, $cmb_center, $this->input->post('childGrade'.$i), $this->input->post('childSession'.$i)))
						{
							echo("<b>CLASS FULL</b> for Center: ".$cmb_center.", Grade: ".$this->input->post('childGrade'.$i).", Session: ".$this->input->post('childSession'.$i));
							die;
						}

                        if (!$this->Walk_proxy->isValidDOB($this->input->post('childDOB' . $i)))
                        {
                            echo("<b>Child #".$i." DOB must be on or before ".$this->config->item('dob_thr_date')."</b>");
                            die;
                        }
					}
				}
			}

			//Financial
			$rules['donationamount'] = "trim|numeric|max_length[8]";
			
			$this->validation->set_rules($rules);
			$validationPassed = $this->validation->run();
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_for_register_existing( $this->validation->error_string, $cwr_registrant_home_value ) );
			}
			
			die;
		}

		public function validate_step2()
		{
			$rules['displayName'] = "trim|required|max_length[25]";
			$rules['numWalkers'] = "trim|required|numeric";
			$rules['numRunners'] = "trim|required|numeric";
			$rules['includedTShirtSize'] = "trim|required";
			$rules['goal'] = "trim|numeric";
			$rules['donation'] = "trim|numeric";
			
			if( $this->input->post('additionalTShirts') > 0 )
			{
				for( $i = 1; $i <= $this->input->post('additionalTShirts'); $i++ )
				{
					$rules['additionalTShirtSize' . $i] = "trim|required";
				}
			}
			
			$this->validation->set_rules($rules);
			
			$validationPassed = $this->validation->run();
			
			if( $this->input->post('numWalkers') == 0 && $this->input->post('numRunners') == 0 )
			{
				$validationPassed = FALSE;
				$this->validation->error_string .= "<p>You must enter at least one walker or one runner.</p>";
			}
			
			if($validationPassed)
			{
				echo( 'VALIDATION_SUCCESS' );
			}
			else
			{
				echo( $this->clean_validation_errors_for_step2( $this->validation->error_string ) );
			}
			
			die;
		}	
		
		public function validate_balavihar_attendance()
		{
			echo( 'VALIDATION_SUCCESS' );
			
			die;
		}

		public function validate_balavihar_attendance_update()
		{
			echo( 'VALIDATION_SUCCESS' );
			
			die;
		}

		private function clean_validation_errors_for_step1( $valErrors )
		{
			$valErrors = str_replace("cmbCenter", "CMB Center", $valErrors);
			
			if( $this->input->post('cmbCenter') != "" )
			{
				if( $this->input->post('cmbCenter') == "Andover" )
				{
					$valErrors = str_replace("firstName", "Primary First Name", $valErrors);
					$valErrors = str_replace("lastName", "Primary Last Name", $valErrors);
					$valErrors = str_replace("question", "Security question", $valErrors);
					$valErrors = str_replace("secretPhrase", "Security question answer", $valErrors);
					$valErrors = str_replace("gender", "Primary Gender", $valErrors);
					$valErrors = str_replace("primaryEmail", "Primary Email", $valErrors);
					$valErrors = str_replace("primaryEmailConfirm", "Confirm Primary Email", $valErrors);
					$valErrors = str_replace("homePhoneNumber", "Primary Home Phone Number", $valErrors);
					$valErrors = str_replace("mobilePhoneNumber", "Primary Mobile Phone Number", $valErrors);
					if ( $this->input->post('company') != "" )
						$valErrors = str_replace("company", "Company name", $valErrors);
			
           	 		if( $this->input->post('spouseFirstName') != "" )
					{
						$valErrors = str_replace("spouseFirstName", "Spouse First Name", $valErrors);
						$valErrors = str_replace("spouseLastName", "Spouse First Name", $valErrors);
						$valErrors = str_replace("spouseGender", "Spouse Gender", $valErrors);
						$valErrors = str_replace("spouseEmail", "Spouse Email", $valErrors);
						$valErrors = str_replace("spousePhone", "Spouse Home Phone", $valErrors);
						$valErrors = str_replace("spouseMobilePhone", "Spouse Mobile Phone", $valErrors);
					}

					$valErrors = str_replace("homeAddress1", "Home Address 1", $valErrors);
					if ($this->input->post('homeAddress2') != "")
						$valErrors = str_replace("homeAddress2", "Home Address 2", $valErrors);
					$valErrors = str_replace("city", "City", $valErrors);
					$valErrors = str_replace("state", "State", $valErrors);
					$valErrors = str_replace("zipCode", "Zip Code", $valErrors);
			
					//$valErrors = str_replace("lifeMember", "Life Member", $valErrors);
					$valErrors = str_replace("primaryAttendSatsang", "Primary Member Attend Satsang", $valErrors);			
				

					//$valErrors = str_replace("donationopt", "Make a Donation", $valErrors);

            		if( $this->input->post('numChildren') > 0 )
					{
						for( $i = 1; $i <= $this->input->post('numChildren'); $i++ )
						{
							$valErrors = str_replace("childFN" . $i, "Child #' . $i . ' First Name", $valErrors);
							$valErrors = str_replace("childLN" . $i, "Child #' . $i . ' Last Name", $valErrors);					
							$valErrors = str_replace("childG" . $i, "Child #' . $i . ' Gender", $valErrors);
							if ($this->input->post('childEM' . $i) != "")
								$valErrors = str_replace("childEM" . $i, "Child #' . $i . ' Email", $valErrors);
							$valErrors = str_replace("childDOB" . $i, "Child #' . $i . ' Date of Birth", $valErrors);
							$valErrors = str_replace("childGrade" . $i, "Child #' . $i . ' Grade", $valErrors);
							$valErrors = str_replace("childSession" . $i, "Child #' . $i . ' Session", $valErrors);
							/*
							for( $j = 1; $j <= 7; $j++ )
							{
								if( isset( $_POST['child' . $i . 'Lang'] ) )
								{
									$valErrors = str_replace("Child #' . $i . ' Language Level", $valErrors);
								}
							}
							*/
						}
					}
					
					$valErrors = str_replace("donationamount", "Make a donation", $valErrors);
				}
				else
				{
					$valErrors = str_replace("firstName1", "Primary First Name", $valErrors);
					$valErrors = str_replace("lastName1", "Primary Last Name", $valErrors);
					$valErrors = str_replace("question1", "Security question", $valErrors);
					$valErrors = str_replace("secretPhrase1", "Security question answer", $valErrors);
					$valErrors = str_replace("gender1", "Primary Gender", $valErrors);
					$valErrors = str_replace("primaryEmail1", "Primary Email", $valErrors);
					$valErrors = str_replace("homePhoneNumber1", "Primary Home Phone Number", $valErrors);
					$valErrors = str_replace("mobilePhoneNumber1", "Primary Mobile Phone Number", $valErrors);
					if ( $this->input->post('company1') != "" )
						$valErrors = str_replace("company1", "Company name", $valErrors);
			
           	 		if( $this->input->post('spouseFirstName1') != "" )
					{
						$valErrors = str_replace("spouseFirstName1", "Spouse First Name", $valErrors);
						$valErrors = str_replace("spouseLastName1", "Spouse First Name", $valErrors);
						$valErrors = str_replace("spouseGender1", "Spouse Gender", $valErrors);
						$valErrors = str_replace("spouseEmail1", "Spouse Email", $valErrors);
						$valErrors = str_replace("spousePhone1", "Spouse Home Phone", $valErrors);
						$valErrors = str_replace("spouseMobilePhone1", "Spouse Mobile Phone", $valErrors);
					}

					$valErrors = str_replace("homeAddress1mw", "Home Address 1", $valErrors);
					if ($this->input->post('homeAddress2mw') != "")
						$valErrors = str_replace("homeAddress2mw", "Home Address 2", $valErrors);
					$valErrors = str_replace("city1", "City", $valErrors);
					$valErrors = str_replace("state1", "State", $valErrors);
					$valErrors = str_replace("zipCode1", "Zip Code", $valErrors);
			
					//$valErrors = str_replace("lifeMember1", "Life Member", $valErrors);

					//$valErrors = str_replace("donationopt1", "Make a Donation", $valErrors);

            		if( $this->input->post('numChildren1') > 0 )
					{
						for( $i = 1; $i <= $this->input->post('numChildren1'); $i++ )
						{
							$valErrors = str_replace("childFNmw" . $i, "Child #' . $i . ' First Name", $valErrors);
							$valErrors = str_replace("childLmwN" . $i, "Child #' . $i . ' Last Name", $valErrors);					
							$valErrors = str_replace("childGmw" . $i, "Child #' . $i . ' Gender", $valErrors);
							if ($this->input->post('childEMmw' . $i) != "")
								$valErrors = str_replace("childEMmw" . $i, "Child #' . $i . ' Email", $valErrors);
							$valErrors = str_replace("childDOBmw" . $i, "Child #' . $i . ' Date of Birth", $valErrors);
							$valErrors = str_replace("childGrademw" . $i, "Child #' . $i . ' Grade", $valErrors);
							/*
							for( $j = 1; $j <= 7; $j++ )
							{
								if( isset( $_POST['child' . $i . 'Lang'] ) )
								{
									$valErrors = str_replace("Child #' . $i . ' Language Level", $valErrors);
								}
							}
							*/
						}
					}
					
					$valErrors = str_replace("donationamount1", "Make a donation", $valErrors);
				}
			}
						
			return $valErrors;
		}
				
		private function clean_validation_errors_for_edit_account( $valErrors )
		{
			if( $this->input->post('password') != "" )
			{
				$valErrors = str_replace("password", "Password", $valErrors);
				$valErrors = str_replace("passconf", "Entered Password", $valErrors);
			}

			$valErrors = str_replace("question", "Security question", $valErrors);
			$valErrors = str_replace("secretPhrase", "Security question answer", $valErrors);
			$valErrors = str_replace("primaryEmail", "Primary Email", $valErrors);
			$valErrors = str_replace("homePhoneNumber", "Primary Home Phone Number", $valErrors);
			$valErrors = str_replace("mobilePhoneNumber", "Primary Mobile Phone Number", $valErrors);
			
           	if( $this->input->post('spouseEmail') != "" )
			{
				$valErrors = str_replace("spouseEmail", "Spouse Email", $valErrors);
			}

           	if( $this->input->post('spousePhone') != "" )
			{
				$valErrors = str_replace("spousePhone", "Spouse Home Phone", $valErrors);
			}

           	if( $this->input->post('spouseMobilePhone') != "" )
			{
				$valErrors = str_replace("spouseMobilePhone", "Spouse Mobile Phone", $valErrors);
			}

			$valErrors = str_replace("homeAddress1", "Home Address 1", $valErrors);
			if ($this->input->post('homeAddress2') != "")
				$valErrors = str_replace("homeAddress2", "Home Address 2", $valErrors);
			$valErrors = str_replace("city", "City", $valErrors);
			$valErrors = str_replace("state", "State", $valErrors);
			$valErrors = str_replace("zipCode", "Zip Code", $valErrors);			
						
			return $valErrors;
		}

		private function clean_validation_errors_for_admin_edit_account( $valErrors )
		{
			$valErrors = str_replace("primaryEmail", "Primary Email", $valErrors);
			$valErrors = str_replace("homePhoneNumber", "Primary Home Phone Number", $valErrors);
			$valErrors = str_replace("mobilePhoneNumber", "Primary Mobile Phone Number", $valErrors);
			
           	if( $this->input->post('spouseEmail') != "" )
			{
				$valErrors = str_replace("spouseEmail", "Spouse Email", $valErrors);
			}

           	if( $this->input->post('spousePhone') != "" )
			{
				$valErrors = str_replace("spousePhone", "Spouse Home Phone", $valErrors);
			}

           	if( $this->input->post('spouseMobilePhone') != "" )
			{
				$valErrors = str_replace("spouseMobilePhone", "Spouse Mobile Phone", $valErrors);
			}

			$valErrors = str_replace("homeAddress1", "Home Address 1", $valErrors);
			if ($this->input->post('homeAddress2') != "")
				$valErrors = str_replace("homeAddress2", "Home Address 2", $valErrors);
			$valErrors = str_replace("city", "City", $valErrors);
			$valErrors = str_replace("state", "State", $valErrors);
			$valErrors = str_replace("zipCode", "Zip Code", $valErrors);			
						
			return $valErrors;
		}

		private function clean_validation_errors_for_register_existing( $valErrors, $cwr_registrant_home_value )
		{
			$cwr_registrant_home_value = Cwr_registrant_member_homepage_value::cast($cwr_registrant_home_value);
			
			//Primary
			/* if($cwr_registrant_home_value->getCMBCenter() == "Andover")
			{
				$valErrors = str_replace("primaryAttendSatsang", "Primary Member Preferred Satsang Session", $valErrors);			
			} */
						
			//Spouse
			if ($cwr_registrant_home_value->getSpouseFirstName() != "")
			{
				if($cwr_registrant_home_value->getCMBCenter() == "Andover")
				{
					$valErrors = str_replace("spouseAttendSatsang", "Spouse Preferred Satsang Session", $valErrors);			
				}
			}

           	//Children
			$numChildren = count($cwr_registrant_home_value->getChildInfo());
			if( $numChildren > 0 )
			{
				$childInfoArray = $cwr_registrant_home_value->getChildInfo();
				$i = 0;
				for( $k = 0; $k < $numChildren; $k++ )
				{					
					$childInfo = $childInfoArray[$k];
					
					if ($childInfo[7] == "1")
					{
						if ($this->input->post('childRemove'.($i+1)) == "No")
						{
							if($cwr_registrant_home_value->getCMBCenter() == "Andover")
							{
								$valErrors = str_replace('childSession'.($i+1),'Child'.($i+1).' session', $valErrors);
							}

							$valErrors = str_replace("existChildEmail".($i+1),"Child".($i+1)." Email", $valErrors);
							$valErrors = str_replace("childGrade".($i+1),"Child".($i+1)." grade", $valErrors);
						}
					
						$i ++;
					} //if ($childInfo == "1")
				} //for( $k = 0; $k < $numChildren; $k++ )
			}
			$numEnabledChildren = $i;

			//Additional Children
           	if ((6-$numEnabledChildren) > 0)
			{
				if ($this->input->post('numChildren') != "")
				{
					$numAddChildren = $this->input->post('numChildren');
					for( $i = ($numEnabledChildren+1); $i < ($numEnabledChildren + $numAddChildren + 1); $i++ )
					{
						$valErrors = str_replace('childFN' . $i,'Child'.$i." First Name", $valErrors);
						$valErrors = str_replace('childLN' . $i,'Child'.$i." Last Name", $valErrors);
						$valErrors = str_replace('childG' . $i,'Child'.$i." Gender", $valErrors);
						
						if ($this->input->post('childEM' . $i) != "")
							$valErrors = str_replace('childEM' . $i,'Child'.$i." Email", $valErrors);

						$valErrors = str_replace('childDOB' . $i,'Child'.$i." Date of Birth", $valErrors);
						$valErrors = str_replace('childGrade' . $i,'Child'.$i." Grade", $valErrors);
						/* if($cwr_registrant_home_value->getCMBCenter() == "Andover")
							$valErrors = str_replace('childSession' . $i,'Child'.$i." Balavihar Session", $valErrors); */
					}
				}
			}

			$valErrors = str_replace("donationamount", "Make a Donation", $valErrors);
			
			return $valErrors;
		}

		private function clean_validation_errors_release_check( $valErrors, $RegIdArray )
		{

			if (count($RegIdArray) > 0)
			{
				//CheckInfo
				for( $i = 0; $i < count($RegIdArray); $i++ )
				{
					$checknum = $this->input->post('crhid'.$RegIdArray[$i]);
					if ($checknum != "")
					{
						$valErrors = str_replace("'crhid'.$RegIdArray[$i]", "Check #", $valErrors);
					}
				}					
			}
			
			return $valErrors;
		}

		private function clean_validation_errors_for_step2( $valErrors )
		{
			$valErrors = str_replace("individualOrFamily", "Individual or family registration", $valErrors);
			$valErrors = str_replace("displayName", "Display name", $valErrors);
			$valErrors = str_replace("numWalkers", "Number of walkers", $valErrors);
			$valErrors = str_replace("numRunners", "Number of runners", $valErrors);
			$valErrors = str_replace("includedTShirtSize", "Size for included T-Shirt", $valErrors);
			$valErrors = str_replace("hearAbout", "How did you hear about", $valErrors);
			$valErrors = str_replace("chinmayaMissionBostonMember", "Are you a member", $valErrors);
			$valErrors = str_replace("additionalTShirtSize", "Size for extra T-Shirt #", $valErrors);
			
			return $valErrors;
		}	
	}

?>